﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Text;
using AdventureWorks.Application.ViewModels.Production.Default;

namespace AdventureWorks.LinqDataSource {
  public partial class AdventureWorks {
    public IEnumerable<ProductSelector> FetchAllProducts(int max) {
      return (
        from prod in this.Production_Product
        select new ProductSelector {
          ProductID = prod.ProductID,
          ProductName = prod.Name,
          NoInStock = prod.Production_ProductInventory.Count,
          ToBeReordered = prod.Production_ProductInventory.Count < prod.ReorderPoint
        }
              ).Take(max).AsEnumerable();
    }

    internal IEnumerable<ProductSelector> FetchTopProducts(int max) {
      return (
        from prod in this.Production_Product
        orderby prod.Purchasing_PurchaseOrderDetail.Count descending
        select new ProductSelector {
          ProductID = prod.ProductID,
          ProductName = prod.Name
        }
              ).Take(max).AsEnumerable();
    }
  }
}
